/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class UnsealTheSafe {
public:
    long long countPasswords(int N);
};
Int dp[31][10];
Int go(int N, int cur_char) {
    if ( N==0 ) {
        return 1LL;
    }

    Int &ways=dp[N][cur_char];
    if (ways!=-1)return ways;
    ways=0;
    if ( cur_char==1 ) {
        ways+= ( go(N-1,2)+go(N-1,4) );
    }
    if ( cur_char==2 ) {
        ways+= ( go(N-1,1)+go(N-1,3)+go(N-1,5) );
    }
    if ( cur_char==3 ) {
        ways+= ( go(N-1,2)+go(N-1,6) );
    }
    if ( cur_char==4 ) {
        ways+= ( go(N-1,1)+go(N-1,5)+go(N-1,7) );
    }
    if ( cur_char==5 ) {
        ways+= ( go(N-1,2)+go(N-1,4)+go(N-1,6)+go(N-1,8) );
    }
    if ( cur_char==6 ) {
        ways+= ( go(N-1,3)+go(N-1,5)+go(N-1,9) );
    }
    if ( cur_char==7 ) {
        ways+= ( go(N-1,4)+go(N-1,8)+go(N-1,0) );
    }
    if ( cur_char==8 ) {
        ways+= ( go(N-1,7)+go(N-1,5)+go(N-1,9) );
    }
    if ( cur_char==9 ) {
        ways+= ( go(N-1,6)+go(N-1,8) );
    }
    if ( cur_char==0 ) {
        ways+= ( go(N-1,7) );
    }
    return ways;
}
long long UnsealTheSafe :: countPasswords(int N) {
    long long retval=0;
    SET(dp,-1);
    for (int i=0;i<=9;++i) {
        retval+= go(N-1,i);
    }
    return retval;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, int p0, bool hasAnswer, long long p1) {
    cout << "Test " << testNum << ": [" << p0;
    cout << "]" << endl;
    UnsealTheSafe *obj;
    long long answer;
    obj = new UnsealTheSafe();
    clock_t startTime = clock();
    answer = obj->countPasswords(p0);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p1 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == p1;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    int p0;
    long long p1;

    {
        // ----- test 0 -----
        p0 = 2;
        p1 = 26ll;
        all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        p0 = 3;
        p1 = 74ll;
        all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        p0 = 25;
        p1 = 768478331222ll;
        all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
